package com.xbongbong.pro.message.base;/*/*/


import com.alibaba.fastjson.JSONObject;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.interfaces.IPushSet;
import com.xbongbong.pro.message.model.PushSetModel;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息设置抽象类
 *
 * @author GuoJun.HU
 * @since V1.0
 * @date 2019/2/19 10:37
 */
@Getter
@Setter
public abstract class AbstractPushSet implements IPushSet {

    protected Integer id;

    protected String corpid;

    protected Integer refEntity;

    protected Integer type;

    protected Integer subType;

    protected Integer enable;

    protected Integer addTime;

    protected Integer updateTime;

    protected Integer del;

    protected Integer templateId;

    /**
     * 获取时间jsonStr
     * @param type
     * @param time
     * @param timeInterval
     * @param timeIntervalType
     * @return
     * @author chy
     * @time 2016-11-9 下午9:10:03
     */
    @Override
    public String toTimeJsonStr(Integer type, Integer time, Integer timeInterval, Integer timeIntervalType, Integer loop){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("type", type);
        jsonObject.put("time", time);
        jsonObject.put("timeInterval", timeInterval);
        jsonObject.put("timeIntervalType", timeIntervalType);
        jsonObject.put("loop", loop);
        return jsonObject.toJSONString();
    }

    /**
     * 保存时获取时间jsonStr
     * @param jsonObject
     * @return
     * @author chy
     * @time 2016-11-15 下午3:29:45
     */
    public String getTimeJsonStr(JSONObject jsonObject){
        JSONObject retJson = getTimeJson(jsonObject);
        return retJson.toJSONString();
    }


    @Override
    public String toPushObjectJsonStr(Integer pushObjectType, List<Integer> pushRole, List<Long> pushDep, List<String> pushUser){

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pushObjectType", pushObjectType);
        jsonObject.put("pushRole", pushRole);
        jsonObject.put("pushDep", pushDep);
        jsonObject.put("pushUser", pushUser);

        return jsonObject.toJSONString();
    }

    /**
     * 转换成数据库存储对应的entity
     * @param pushObject
     * @param pushTime
     * @param attrEntity
     * @return
     * @author chy
     * @time 2016-10-27 下午5:22:12
     */
    @Override
    public abstract PushSetEntity toPushSetEntity(String pushObject, String pushTime, String attrEntity);

    /**
     * 获取对应类型的推送设置列表
     * 客户自定义字段提醒需要attrList， 其他不需要
     * @param corpid
     * @return
     * @author chy
     * @time 2016-11-9 下午2:29:29
     */
    public List<PushSetEntity> getPushSetList(String corpid, Integer type, PushSetModel pushSetModel, List<String> attrList, Long templateId){
        List<PushSetEntity> pushSetList = new ArrayList<PushSetEntity>();

        if(type == PushTypeEnum.CUSTOMER_REMIND.getCode()){
            //客户自定义使用的是attr
            pushSetList = getPushSet(corpid, attrList, pushSetModel, templateId);
        }else{
            List<PushTypeEnum> pushTypeEnumList =  PushTypeEnum.getAllEnumByType(type);
            for(PushTypeEnum pushTypeEnum : pushTypeEnumList){
                int subType = pushTypeEnum.getSubCode();
                PushSetEntity pushSetEntity = getPushSet(corpid, subType, pushSetModel);
                pushSetList.add(pushSetEntity);
            }
        }

        return pushSetList;
    }

    /**
     * 获取对应类型的推送设置
     * @param corpid    公司id
     * @param subType   类型
     * @param pushSetModel  model
     * @return PushSetEntity
     * @author chy
     * @date  2016-11-9 下午2:29:29
     */
    public abstract PushSetEntity getPushSet(String corpid, Integer subType, PushSetModel pushSetModel);

    /**
     * 获取对应类型的推送设置
     * @param corpid 公司id
     * @param attr 字段
     * @param pushSetModel model
     * @return PushSetEntity
     * @author chy
     * @date 2016-11-9 下午2:29:29
     */
    public abstract PushSetEntity getPushSet(String corpid, String attr, PushSetModel pushSetModel);

    /**
     * Description:
     *
     * @param corpid       公司id
     * @param attrList         自定义字段名
     * @param pushSetModel
     * @param templateId   模板id
     * @return PushSetEntity
     * @author 魏荣杰
     * @date 2018/12/28 10:10
     * @version multi-template
     * @since multi-template
     * Modified by:
     */
    public abstract List<PushSetEntity> getPushSet(String corpid, List<String> attrList, PushSetModel pushSetModel, Long templateId);
    /**
     * 每个推送设置时间处理有所不同，每个推送各自实现
     * @param jsonObject
     * @return
     * @author chy
     * @time 2016-11-15 下午3:35:59
     */
    public abstract JSONObject getTimeJson(JSONObject jsonObject);
}
